#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
//#include <ctype.h>
//
//
//using namespace std;
//
//struct st { int x; int *y; }*pt;
//
//int main()
//{
//    int x = 2;
//    cout << (x *= x+1 );
//    return 0;
//}


/*
    int minOperations(vector<int>& nums, int x) {
        int left = 0;
        int right = nums.size() - 1;
        int temp = x;
        int ret = 0;
        while (left < right && temp > 0) {
            if (nums[left] <= temp)
            {   ON:
                if (nums[left] >= nums[right])
                {
                    temp -= nums[left++];
                    ret++;

                }
                else
                {
                    goto IN;
                }
            }
            else if (nums[right] <= temp) {
                IN:
                //if (nums[right] >= nums[left])
                //{/
                    temp -= nums[right--];

                    ret++;

                //}
                //else
                //{
                 //   goto ON;
                //}
            }
            else {
                return -1;
            }
        }
        return ret;
    }
    int main()
    {
        vector<int> i{ 3,2,20,1,1,3 };
        cout<<minOperations(i, 10);
        return 0;
}


    class Solution {
    public:
        int minOperations(vector<int>& nums, int x) {
            int ret = -1;
            int sum = 0;
            for (auto d : nums) {
                sum += d;
            }
            int ra = sum - x;
            if (ra < 0)
                return -1;

            for (int left = 0, right = 0, temp = 0; right < nums.size(); right++) {
                temp += nums[right];
                while (temp > ra)
                    temp -= nums[left++];
                if (temp == ra) {
                    ret = max(ret, right - left + 1);
                }
            }
            if (ret == -1)
                return -1;
            else
                return nums.size() - ret;
        }
    };*/